#include "stdafx.h"

#include "gtest/gtest.h"
#include "Player.h"

TEST(domino, player_HappyDay) {
	_CrtMemState _ms;
	_CrtMemCheckpoint(&_ms);
	{
		dgame::Player player("KOTOTYT");
		ASSERT_EQ(player.getScore(), 0);
		ASSERT_EQ(player.getName(), "KOTOTYT");
		dgame::DominoManager dM = player.getDominoes();
		ASSERT_EQ(dM.size(), 0);
	}
	_CrtMemDumpAllObjectsSince(&_ms);
}

TEST(domino, player_addDomino) {
	_CrtMemState _ms;
	_CrtMemCheckpoint(&_ms);
	{
		dgame::Player player("KOTOTYT");
		player.addDomino(dgame::Domino(0,0));
		ASSERT_EQ(player.getScore(), 0);
		ASSERT_EQ(player.getName(), "KOTOTYT");
		dgame::DominoManager dM = player.getDominoes();
		ASSERT_EQ(dM.size(), 1);
		ASSERT_EQ(dM[0], dgame::Domino(0,0));
	}
	_CrtMemDumpAllObjectsSince(&_ms);
}

TEST(domino, player_deleteDomino) {
	_CrtMemState _ms;
	_CrtMemCheckpoint(&_ms);
	{
		dgame::Player player("KOTOTYT");
		{
			player.addDomino(dgame::Domino(0,0));
		}
		player.addDomino(dgame::Domino(0,1));
		player.deleteDomino(dgame::Domino(0, 0));
		ASSERT_EQ(player.getScore(), 0);
		ASSERT_EQ(player.getName(), "KOTOTYT");
		dgame::DominoManager dM = player.getDominoes();
		ASSERT_EQ(dM.size(), 1);
		ASSERT_EQ(dM[0], dgame::Domino(0,1));
	}
	_CrtMemDumpAllObjectsSince(&_ms);
}

TEST(domino, player_deleteDomino_dominoNotFoundException) {
	_CrtMemState _ms;
	_CrtMemCheckpoint(&_ms);
	{
		dgame::Player player("KOTOTYT");
		{
			player.addDomino(dgame::Domino(0,0));
		}
		player.addDomino(dgame::Domino(0,1));
		player.deleteDomino(dgame::Domino(0, 0));
		ASSERT_THROW(player.deleteDomino(dgame::Domino(2,3)), dgame::DominoNotFoundedException);
		dgame::DominoManager dM = player.getDominoes();
		ASSERT_EQ(dM.size(), 1);
	}
	_CrtMemDumpAllObjectsSince(&_ms);
}

TEST(domino, player_intScore) {
	_CrtMemState _ms;
	_CrtMemCheckpoint(&_ms);
	{
		dgame::Player player("KOTOTYT");
		{
			player.addDomino(dgame::Domino(0,0));
		}
		player.incScore(100);
		ASSERT_EQ(player.getScore(), 100);
		player.incScore(-30);
		ASSERT_EQ(player.getScore(), 70);
	}
	_CrtMemDumpAllObjectsSince(&_ms);
}

TEST(domino, player_equals) {
	_CrtMemState _ms;
	_CrtMemCheckpoint(&_ms);
	{
		dgame::Player player("KOTOTYT");
		ASSERT_TRUE(player == dgame::Player("KOTOTYT"));
		ASSERT_FALSE(player == dgame::Player("LOL"));
	}
	_CrtMemDumpAllObjectsSince(&_ms);
}